<template>
  <section>

    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true">
        <el-form-item>
          <template>
            <div style="margin-top: 10px;">
              <span>tips：</span>
              <div style="display: inline-block;width: 400px;">
                <el-input v-model="tip" placeholder="请输入内容"></el-input>
              </div>
            </div>
          </template>
        </el-form-item>
      </el-form>
    </el-col>

    <el-table :data="activePlantData" style="width: 400px;" border>
      <el-table-column prop="name" label="名称">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div style="margin-left: 5px;">
            <el-button type="danger" icon="close" size="small" @click="close_active(scope.row.name)" v-if="scope.row.active_first_order == '1'"></el-button>
            <el-button type="success" icon="check" size="small" @click="open_active(scope.row.name)" v-else></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

  </section>
</template>

<script type="text/ecmascript-6">
  import util from '../../util'
  import { apiTree } from '../../apiTree'

  export default {
    data() {
      return {
        activePlantData: [],
        total: 0,
        tip: ''
      }
    },
    methods: {
      init() {
        apiTree('firstOrder/index', 'tools/getPlantName').then((res) => {
          if (res.s === 1) {
            this.activePlantData = res.d.data
            this.total = res.d.total_num
          }
        })
      },
      // 关闭活动
      close_active(_name) {
        this.$prompt('请输入tips(不输入即为旧版本默认tips)', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({ value }) => {
          this.setActiveStatus({name: _name, tip: value})
        }).catch(() => {});
      },
      // 开启活动
      open_active(_name) {
        if (util.isEmpty(this.tip)) {
          this.$message.error('tip提示为空!')
          return
        }
        this.setActiveStatus({name: _name, tip: this.tip})
      },
      setActiveStatus(param) {
        apiTree('firstOrder/index', 'tools/setActiveStatus', param).then((res) => {
          if (res.s === 1) {
            this.$message({
              message: '提交成功',
              type: 'success'
            });
            this.init();
          } else {
            this.$message.error(res.err_str)
            return
          }
        })
      }
    },
    created() {
      this.init();
    }
  }
</script>

<style scoped>

</style>